<template>
  <div>
    <h1> 父组件向子组件通信 </h1>
    <child 
      :msg="message" 
      @getChildrenData="count += $event" 
      @increased="increased" 
      @decreased="decreased"
      :putArr="arr"
      :warnMessage="warnMessage"
      :fromParent="fromParent"
    ></child>
    <div>
      <span> {{ count }} </span>
    </div>
    <div>
      <h3> 跨级组建之间的通信 </h3>
      <span> {{ info }} </span>
    </div>
    <div>
      {{ fromParent }}
    </div>
  </div>
</template>

<script>
  import child from './child.vue'
  import middleware from './middleware' 
  export default {
    data: function () {
      return {
        message: "从父组件中传递进来的值",
        count: 0,
        arr: [1, 2, 3, 4, 5],
        warnMessage: "this is a message",
        info: 'heiheihei',
        fromParent: '初始值',
      }
    },
    components: {
      child,
    },
    created: function () {
      console.log(middleware)
      middleware.$on('say-hello', info => this.info = info)
    },
    methods: {
      increased: function () {
        return this.count += 1
      },
      decreased: function () {
        return this.count > 0 ? this.count-= 1 : 0 
      }
    }
  }
</script>

<style scoped>
  
</style>